<template>
  <div>
    <!-- 原生写法 -->
    <!-- <svg>
      <use xlink:href="#icon-fullscreen"></use>
    </svg> -->
    <svg-icon
      v-if="isFull"
      class="myIcon"
      icon-class="exit-fullscreen"
      @click="handleClickScreen"
    ></svg-icon>
    <svg-icon
      v-else
      class="myIcon"
      icon-class="fullscreen"
      @click="handleClickScreen"
    ></svg-icon>
  </div>
</template>

<script>
import ScreenFull from "screenfull";

export default {
  name: "ScreenFull",
  data() {
    return {
      isFull: false,
    };
  },
  methods: {
    handleClickScreen() {
      if (ScreenFull.isEnabled) {
        // 支持实现全屏功能
        ScreenFull.toggle();
        this.isFull = !this.isFull;
      } else {
        this.$message.error("你的浏览器版本太低,不支持全屏功能");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.myIcon {
  fill: white;
  cursor: pointer;
}
</style>